/*     */ package com.zimbra.cs.gal;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AccountConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.soap.SoapProtocol;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AuthToken;
/*     */ import com.zimbra.cs.account.DataSource;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Provisioning.SearchGalResult;
/*     */ import com.zimbra.cs.account.gal.GalOp;
/*     */ import com.zimbra.cs.account.gal.GalUtil;
/*     */ import com.zimbra.cs.account.ldap.LdapGalMapRules;
/*     */ import com.zimbra.cs.index.SearchParams;
/*     */ import com.zimbra.cs.index.SortBy;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import com.zimbra.soap.account.type.MemberOfSelector;
/*     */ import com.zimbra.soap.type.GalSearchType;
/*     */ import java.util.EnumSet;
/*     */ import org.dom4j.QName;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class GalSearchParams
/*     */ {
/*     */   private GalSearchConfig mConfig;
/*  46 */   private GalSearchType mType = GalSearchType.account;
/*     */   private int mLimit;
/*     */   private Integer mLdapLimit;
/*     */   private int mPageSize;
/*     */   private String mQuery;
/*     */   private String mSearchEntryByDn;
/*     */   private GalSyncToken mSyncToken;
/*     */   private Provisioning.SearchGalResult mResult;
/*     */   private ZimbraSoapContext mSoapContext;
/*     */   private Account mAccount;
/*     */   private String mUserAgent;
/*     */   private Account mGalSyncAccount;
/*     */   private Domain mDomain;
/*     */   private SearchParams mSearchParams;
/*     */   private GalSearchResultCallback mResultCallback;
/*     */   private GalSearchQueryCallback mExtraQueryCallback;
/*     */   private Element mRequest;
/*     */   private SoapProtocol mProxyProtocol;
/*     */   private QName mResponse;
/*     */   private DataSource mDataSource;
/*     */   private boolean mIdOnly;
/*     */   private boolean mNeedCanExpand;
/*     */   private boolean mNeedIsOwner;
/*     */   private MemberOfSelector mNeedIsMember;
/*     */   private boolean mNeedSMIMECerts;
/*     */   private boolean mFetchGroupMembers;
/*     */   private GalOp mOp;
/*     */   
/*     */   public GalSearchParams(Account account)
/*     */   {
/*  76 */     this.mAccount = account;
/*  77 */     this.mResult = Provisioning.SearchGalResult.newSearchGalResult(null);
/*  78 */     this.mResponse = AccountConstants.SEARCH_GAL_RESPONSE;
/*     */   }
/*     */   
/*     */   public GalSearchParams(Account account, ZimbraSoapContext ctxt) {
/*  82 */     this(account);
/*  83 */     this.mSoapContext = ctxt;
/*     */   }
/*     */   
/*     */   public GalSearchParams(Domain domain, ZimbraSoapContext ctxt) {
/*  87 */     this.mDomain = domain;
/*  88 */     this.mSoapContext = ctxt;
/*     */   }
/*     */   
/*     */   public GalSearchParams(DataSource ds) throws ServiceException {
/*  92 */     this(ds.getAccount());
/*  93 */     this.mDataSource = ds;
/*  94 */     this.mConfig = GalSearchConfig.create(this.mDataSource);
/*     */   }
/*     */   
/*     */   public GalSearchConfig getConfig() {
/*  98 */     return this.mConfig;
/*     */   }
/*     */   
/*     */   public GalSearchType getType() {
/* 102 */     return this.mType;
/*     */   }
/*     */   
/*     */   public int getLimit() {
/* 106 */     return this.mLimit;
/*     */   }
/*     */   
/*     */   public Integer getLdapLimit() {
/* 110 */     return this.mLdapLimit;
/*     */   }
/*     */   
/*     */   public int getPageSize() {
/* 114 */     return this.mPageSize;
/*     */   }
/*     */   
/*     */   public String getQuery() {
/* 118 */     return this.mQuery;
/*     */   }
/*     */   
/*     */   public String getSearchEntryByDn() {
/* 122 */     return this.mSearchEntryByDn;
/*     */   }
/*     */   
/*     */   public String getSyncToken() {
/* 126 */     if (this.mSyncToken == null)
/* 127 */       return null;
/* 128 */     return this.mSyncToken.getLdapTimestamp();
/*     */   }
/*     */   
/*     */   public GalSyncToken getGalSyncToken() {
/* 132 */     return this.mSyncToken;
/*     */   }
/*     */   
/*     */   public Provisioning.SearchGalResult getResult() {
/* 136 */     return this.mResult;
/*     */   }
/*     */   
/*     */   public Account getAccount() {
/* 140 */     return this.mAccount;
/*     */   }
/*     */   
/*     */   public Account getGalSyncAccount() {
/* 144 */     return this.mGalSyncAccount;
/*     */   }
/*     */   
/*     */   public Domain getDomain() throws ServiceException {
/* 148 */     if (this.mDomain != null) {
/* 149 */       return this.mDomain;
/*     */     }
/* 151 */     Domain domain = Provisioning.getInstance().getDomain(this.mAccount);
/* 152 */     if (domain != null) {
/* 153 */       return domain;
/*     */     }
/* 155 */     Account galSyncAcct = getGalSyncAccount();
/* 156 */     if (galSyncAcct != null) {
/* 157 */       domain = Provisioning.getInstance().getDomain(galSyncAcct);
/*     */     }
/* 159 */     if (domain != null) {
/* 160 */       return domain;
/*     */     }
/* 162 */     throw ServiceException.FAILURE("Unable to get domain", null);
/*     */   }
/*     */   
/*     */   public ZimbraSoapContext getSoapContext() {
/* 166 */     return this.mSoapContext;
/*     */   }
/*     */   
/*     */   public AuthToken getAuthToken() {
/* 170 */     if (this.mSoapContext == null) {
/* 171 */       return null;
/*     */     }
/* 173 */     return this.mSoapContext.getAuthToken();
/*     */   }
/*     */   
/*     */   public Account getAuthAccount() throws ServiceException {
/* 177 */     if (this.mSoapContext == null) {
/* 178 */       return getAccount();
/*     */     }
/* 180 */     return Provisioning.getInstance().get(Key.AccountBy.id, this.mSoapContext.getAuthtokenAccountId());
/*     */   }
/*     */   
/*     */   public SearchParams getSearchParams() {
/* 184 */     return this.mSearchParams;
/*     */   }
/*     */   
/*     */   public GalSearchResultCallback getResultCallback() {
/* 188 */     if (this.mResultCallback == null)
/* 189 */       return createResultCallback();
/* 190 */     return this.mResultCallback;
/*     */   }
/*     */   
/*     */   public GalSearchQueryCallback getExtraQueryCallback() {
/* 194 */     return this.mExtraQueryCallback;
/*     */   }
/*     */   
/*     */   public Element getRequest() {
/* 198 */     return this.mRequest;
/*     */   }
/*     */   
/*     */   public SoapProtocol getProxyProtocol() {
/* 202 */     return this.mProxyProtocol == null ? SoapProtocol.Soap12 : this.mProxyProtocol;
/*     */   }
/*     */   
/*     */   public QName getResponseName() {
/* 206 */     return this.mResponse;
/*     */   }
/*     */   
/*     */   public GalOp getOp() {
/* 210 */     return this.mOp;
/*     */   }
/*     */   
/*     */   public boolean isIdOnly() {
/* 214 */     return this.mIdOnly;
/*     */   }
/*     */   
/*     */   public boolean getNeedCanExpand() {
/* 218 */     return this.mNeedCanExpand;
/*     */   }
/*     */   
/*     */   public boolean getNeedIsOwner() {
/* 222 */     return this.mNeedIsOwner;
/*     */   }
/*     */   
/*     */   public MemberOfSelector getNeedIsMember() {
/* 226 */     return this.mNeedIsMember;
/*     */   }
/*     */   
/*     */   public boolean getNeedSMIMECerts() {
/* 230 */     return this.mNeedSMIMECerts;
/*     */   }
/*     */   
/*     */   public void setSearchConfig(GalSearchConfig config) {
/* 234 */     this.mConfig = config;
/*     */   }
/*     */   
/*     */   public void setType(GalSearchType type) {
/* 238 */     this.mType = type;
/*     */   }
/*     */   
/*     */   public void setLimit(int limit) {
/* 242 */     this.mLimit = limit;
/*     */   }
/*     */   
/*     */   public void setLdapLimit(int limit) {
/* 246 */     this.mLdapLimit = Integer.valueOf(limit);
/*     */   }
/*     */   
/*     */   public void setPageSize(int pageSize) {
/* 250 */     this.mPageSize = pageSize;
/*     */   }
/*     */   
/*     */   public void setQuery(String query) {
/* 254 */     this.mQuery = query;
/*     */   }
/*     */   
/*     */   public void setSearchEntryByDn(String dn) {
/* 258 */     this.mSearchEntryByDn = dn;
/*     */   }
/*     */   
/*     */   public void setToken(String token) {
/* 262 */     this.mSyncToken = new GalSyncToken(token);
/*     */   }
/*     */   
/*     */   public void setGalResult(Provisioning.SearchGalResult result) {
/* 266 */     this.mResult = result;
/*     */   }
/*     */   
/*     */   public void createSearchParams(String searchQuery) {
/* 270 */     this.mSearchParams = new SearchParams();
/* 271 */     this.mSearchParams.setLimit(this.mLimit + 1);
/* 272 */     this.mSearchParams.setSortBy(SortBy.NAME_ASC);
/* 273 */     this.mSearchParams.setQueryString(searchQuery);
/* 274 */     this.mSearchParams.setTypes(EnumSet.of(MailItem.Type.CONTACT));
/*     */   }
/*     */   
/*     */   public void parseSearchParams(Element request, String searchQuery) throws ServiceException {
/* 278 */     if ((request == null) || (this.mSoapContext == null)) {
/* 279 */       createSearchParams(searchQuery);
/* 280 */       return;
/*     */     }
/* 282 */     setRequest(request);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 289 */     request.addAttribute("types", MailItem.Type.CONTACT.toString());
/* 290 */     this.mSearchParams = SearchParams.parse(request, this.mSoapContext, searchQuery);
/* 291 */     this.mSearchParams.setTypes(EnumSet.of(MailItem.Type.CONTACT));
/* 292 */     setLimit(this.mSearchParams.getLimit());
/*     */   }
/*     */   
/*     */   public void setResultCallback(GalSearchResultCallback callback) {
/* 296 */     this.mResultCallback = callback;
/*     */   }
/*     */   
/*     */   public GalSearchResultCallback createResultCallback() {
/* 300 */     this.mResultCallback = new GalSearchResultCallback(this);
/* 301 */     return this.mResultCallback;
/*     */   }
/*     */   
/*     */   public void setExtraQueryCallback(GalSearchQueryCallback callback) {
/* 305 */     this.mExtraQueryCallback = callback;
/*     */   }
/*     */   
/*     */   public void setRequest(Element req) {
/* 309 */     this.mRequest = req;
/*     */   }
/*     */   
/*     */   public void setProxyProtocol(SoapProtocol proxyProtocol) {
/* 313 */     this.mProxyProtocol = proxyProtocol;
/*     */   }
/*     */   
/*     */   public void setResponseName(QName response) {
/* 317 */     this.mResponse = response;
/*     */   }
/*     */   
/*     */   public void createSearchConfig(GalSearchConfig.GalType type) throws ServiceException {
/* 321 */     this.mConfig = GalSearchConfig.create(getDomain(), this.mOp, type, this.mType);
/* 322 */     this.mConfig.getRules().setFetchGroupMembers(this.mFetchGroupMembers);
/* 323 */     this.mConfig.getRules().setNeedSMIMECerts(this.mNeedSMIMECerts);
/*     */   }
/*     */   
/*     */   public String generateLdapQuery() throws ServiceException {
/* 327 */     assert (this.mConfig != null);
/* 328 */     String token = this.mSyncToken != null ? this.mSyncToken.getLdapTimestamp(this.mConfig.mTimestampFormat) : null;
/*     */     
/* 330 */     String extraQuery = null;
/* 331 */     if ((GalSearchConfig.GalType.zimbra == this.mConfig.getGalType()) && (this.mExtraQueryCallback != null)) {
/* 332 */       extraQuery = this.mExtraQueryCallback.getZimbraLdapSearchQuery();
/*     */     }
/* 334 */     return GalUtil.expandFilter(this.mConfig.getTokenizeKey(), this.mConfig.getFilter(), this.mQuery, token, extraQuery);
/*     */   }
/*     */   
/*     */   public void setGalSyncAccount(Account acct) {
/* 338 */     this.mGalSyncAccount = acct;
/*     */   }
/*     */   
/*     */   public void setIdOnly(boolean idOnly) {
/* 342 */     this.mIdOnly = idOnly;
/*     */   }
/*     */   
/*     */   public void setNeedCanExpand(boolean needCanExpand) {
/* 346 */     this.mNeedCanExpand = needCanExpand;
/*     */   }
/*     */   
/*     */   public void setNeedIsOwner(boolean needOwnerOf) {
/* 350 */     this.mNeedIsOwner = needOwnerOf;
/*     */   }
/*     */   
/*     */   public void setNeedIsMember(MemberOfSelector needMemberOf) {
/* 354 */     this.mNeedIsMember = needMemberOf;
/*     */   }
/*     */   
/*     */   public void setNeedSMIMECerts(boolean needSMIMECerts) {
/* 358 */     this.mNeedSMIMECerts = needSMIMECerts;
/*     */   }
/*     */   
/*     */   public void setFetchGroupMembers(boolean fetchGroupMembers)
/*     */   {
/* 363 */     this.mFetchGroupMembers = fetchGroupMembers;
/*     */   }
/*     */   
/*     */   public void setOp(GalOp op) {
/* 367 */     this.mOp = op;
/*     */   }
/*     */   
/*     */   public void setUserAgent(String ua) {
/* 371 */     this.mUserAgent = ua;
/*     */   }
/*     */   
/*     */   public String getUserInfo() {
/* 375 */     if (this.mAccount != null) {
/* 376 */       return this.mAccount.getName() + " (" + (this.mUserAgent == null ? "" : this.mUserAgent) + ")";
/*     */     }
/* 378 */     return " (" + (this.mUserAgent == null ? "" : this.mUserAgent) + ")";
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/gal/GalSearchParams.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */